# -*- coding: utf-8 -*-
#===================================================
# @Time : 2021/3/25 16:32                           
# @Author : weni09                                  
# @File : site_config.py
#===================================================
from .fastapi_admin.site import Menu, Site
from admin.filters import TitleLikeFilter,NameLikeFilter,ArticleFilter


home_menu = Menu(name="Home", url="/", icon="fa fa-home")

auth_menu = Menu(
                    name="Auth",
                    children=[
                        Menu(
                            name="User",
                            url="/rest/User",
                            icon="fa fa-user",
                            search_fields=("username",),
                            attrs={
                                "avatar": {"label": "Avatar", "required": False},
                                "last_login":{"label": "Last_Login", "required": False}
                                   },
                        ),
                        Menu(name="Role", url="/rest/Role", icon="fa fa-group",),
                        Menu(name="Permission", url="/rest/Permission", icon="fa fa-user-plus",),
                        Menu(
                            name="AdminLog",
                            url="/rest/AdminLog",
                            icon="fa fa-align-left",
                            search_fields=("action", "admin", "model"),
                            sort_fields=("admin_log_id","created_at")
                        ),
                    ],
                )

content_menu = Menu(
                    name="Content",
                    children=[
                        Menu(
                            name="Article",
                            url="/rest/Article",
                            icon="fa fa-book",
                            search_fields=(TitleLikeFilter,"author"),
                            exclude=('views','slug','body','body_md'),
                            attrs={"views":{"label":"Views","disabled":True},
                                   "author":{"label":"Author","required":False},
                                   "slug":{"label":"Slug","disabled":True},
                                   "summary":{"label":"Summary","required":False},
                                   "img_link":{"label":"Img_Link","required":False},
                                   "is_public":{"label":"Is_Public","required":False},
                                   "is_top":{"label":"Is_Top","required":False},
                                   },

                            custom_filters=[ArticleFilter,]

                        ),
                        Menu(
                            name="Category",
                            url="/rest/Category",
                            icon="fa fa-list",
                            search_fields=(NameLikeFilter,),
                            exclude=('slug',),
                            attrs={"slug":{"label":"Slug","disabled":True}}
                        ),
                        Menu(
                            name="Tag",
                            url="/rest/Tag",
                            icon="fa fa-gear",
                            import_=True,
                            search_fields=(NameLikeFilter,),
                            exclude=('slug',),
                            # custom_filters=[CustomFilter],
                        ),
                    ],
                )

external_menu = Menu(
    name="External",
    children=[
        Menu(
            name="Github",
            url="https://github.com/weni09?tab=repositories",
            icon="fa fa-github",
            external=True,
        ),
        Menu(
            name="Logout",
            url="/logout",
            icon="fa fa-lock",
        ),
    ],
)

# logout_menu = Menu(name="Logout", url="/logout", icon="fa fa-lock",)

site=Site(
            name="FastAPI-Admin",
            login_footer="FASweTAPI ADMIN - FastAPI Admin Dashboard",
            # login_description="FastAPI Admin Dashboard",
            locale="zh-CN",
            locale_switcher=True,
            theme_switcher=True,
            menus=[home_menu,content_menu,auth_menu,external_menu]
        )
